package com.qj.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @desc 拦截器，设置默认值
 * @author dlw
 * @date 2025-05-13 19:55
 */
@Component
public class CustomMetaObjectHandler implements MetaObjectHandler {
    /**
     * @author dlw
     * @description: 新增设置默认值
     * @date 2025/5/14 14:00
     */

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createBy", String.class, "qj");
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "deleteFlag", Integer.class, 0);
        this.strictInsertFill(metaObject, "version", Integer.class, 0);
    }
    /**
     * @author dlw
     * @description: 修改设置默认修改时间和修改人
     * @date 2025/5/14 14:00
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateBy", String.class, "qj");
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }
}
